/*
 * Copyright 2001 Alexander Boverman and the original authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _WT_PROC_SESSION_H
#define _WT_PROC_SESSION_H

#include <tcl.h>
#include "WtMtTable.h"
#include "WtSession.h"

typedef struct WtProcSessionT {
  int initDone;
  Tcl_Obj *id;
  Tcl_Obj *psTable;
  int isNew;
  int isModified;
} WtProcSession;

typedef struct WtPSTableT {
  Tcl_Obj *sharedTable;
  time_t accessTime;
} WtPSTable;

int WtOpenProcSession(WtProcSession *sh, Tcl_Obj *id, Tcl_Interp *interp);
int WtCloseProcSession(WtProcSession *sh, Tcl_Interp *interp);
Tcl_Obj *WtGetProcSessionTable(Tcl_Obj *id);
int WtInitProcSession(WtProcSession *sh, Tcl_Interp *interp);
int WtOpenProcSessionTable(WtProcSession *sh, Tcl_Obj *id,
  Tcl_Interp *interp);
int WtCloseProcSessionTable(WtProcSession *sh, Tcl_Interp *interp);
Tcl_Obj *WtGetProcSessionTable(Tcl_Obj *id);
WtSessionStatus WtGetPSTableStatus(Tcl_Obj *stObj, Tcl_Interp *interp);
int WtDeleteProcSession(WtProcSession *sh, Tcl_Obj *id, Tcl_Interp *interp);
int WtSweepProcSessions(WtProcSession *sh, Tcl_Interp *interp);
int WtProcSessionFinalizeRequest(WtProcSession *sh, Tcl_Interp *interp);
int WtProcSessionCmd(ClientData clientData, Tcl_Interp *interp,
  int objc, Tcl_Obj *const objv[]);
int WtProcSessionCmdHelper(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
void WtProcSessionCmdUsage(Tcl_Interp *interp, Tcl_Obj *cmd);
int WtProcSessionIdCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionCountCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionHasCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionGetCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionSetCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionSetDefaultCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionKeysCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionValuesCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionRemoveCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionRemoveListCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionArrayCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionItemsCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionTouchCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionClearCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionIsAccessedCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionIsModifiedCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionStatusCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionPropertiesCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionClientPropertiesCmd(ClientData clientData,
  Tcl_Interp *interp, WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionDeleteCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionSweepCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionUnloadCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionLoadModuleCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionUnloadModuleCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
int WtProcSessionFinalizeCmd(ClientData clientData, Tcl_Interp *interp,
  WtProcSession *sh, int objc, Tcl_Obj *const objv[]);
Tcl_Obj *WtGetPSStorage(WtProcSession *sh, Tcl_Interp *interp);
void WtInitProcSessionCommands(Tcl_Interp *interp);
Tcl_Obj *WtNewProcSessionObj();
WtProcSession *WtProcSessionRep(Tcl_Obj *obj);
Tcl_Obj *WtNewPSTableObj();
WtPSTable *WtPSTableRep(Tcl_Obj *obj);

extern Tcl_ObjType WtProcSessionType;
extern Tcl_ObjType WtPSTableType;
extern Tcl_HashTable wtPSTables;
extern Tcl_Mutex wtPSTablesLock;

#endif /* !_WT_PROC_SESSION_H */
